-- [tsx]: step3.tsx
local ____lualib = require("lualib_bundle") -- 1
local __TS__Generator = ____lualib.__TS__Generator -- 1
local ____exports = {} -- 1
local ____DoraX = require("DoraX") -- 1
local React = ____DoraX.React -- 1
local ____Dora = require("Dora") -- 2
local App = ____Dora.App -- 3
local Audio = ____Dora.Audio -- 4
local Color = ____Dora.Color -- 7
local Ease = ____Dora.Ease -- 9
local Node = ____Dora.Node -- 11
local Scale = ____Dora.Scale -- 12
local Vec2 = ____Dora.Vec2 -- 16
local thread = ____Dora.thread -- 17
local MUSIC_PATH = "audio/music.mp3" -- 25
local BEAT_INTERVAL_MS = 500 -- 26
local NOTE_SPAWN_OFFSET_MS = 300 -- 27
local songStartTimeSystem = nil -- 33
local audioInstanceRef = {current = nil} -- 34
local isPlayingRef = {current = false} -- 35
local function getSongCurrentTimeMs() -- 41
	if audioInstanceRef.current then -- 41
		do -- 41
			local function ____catch(e) -- 41
				print("Error getting audio current time: " .. tostring(e)) -- 47
				return true, nil -- 48
			end -- 48
			local ____try, ____hasReturned, ____returnValue = pcall(function() -- 48
				local sec = Audio.getCurrentTime(audioInstanceRef.current) -- 44
				return true, sec * 1000 -- 45
			end) -- 45
			if not ____try then -- 45
				____hasReturned, ____returnValue = ____catch(____hasReturned) -- 45
			end -- 45
			if ____hasReturned then -- 45
				return ____returnValue -- 43
			end -- 43
		end -- 43
	end -- 43
	return nil -- 51
end -- 41
local function msToBeat(ms) -- 54
	return ms / BEAT_INTERVAL_MS -- 55
end -- 54
local function beatToScreenY(beat, currentBeat) -- 58
	local beatsAhead = beat - currentBeat -- 59
	return beatsAhead * 100 -- 60
end -- 58
local function Tap(props) -- 73
	return React.createElement( -- 74
		"body", -- 74
		{ -- 74
			type = "Static", -- 74
			scaleX = 0, -- 74
			scaleY = 0, -- 74
			x = props.x, -- 74
			y = props.y, -- 74
			onMount = function(____self) -- 74
				local scaleAction = Scale(0.3, 1, 1) -- 83
				local easedAction = Ease.OutBack(scaleAction) -- 84
				____self:runAction(easedAction) -- 85
			end -- 81
		}, -- 81
		React.createElement("rect-fixture", {width = 250, height = 30}), -- 81
		React.createElement( -- 81
			"draw-node", -- 81
			nil, -- 81
			React.createElement("rect-shape", { -- 81
				width = 250, -- 81
				height = 30, -- 81
				fillColor = 2281766911, -- 81
				borderWidth = 1, -- 81
				borderColor = 4278255615 -- 81
			}) -- 81
		), -- 81
		props.children -- 98
	) -- 98
end -- 73
____exports.GameScene = function() -- 107
	local root = Node() -- 108
	local notesContainer = Node() -- 109
	notesContainer.position = Vec2(0, 0) -- 110
	notesContainer:addTo(root) -- 111
	thread(__TS__Generator(function() -- 114
		if not audioInstanceRef.current then -- 114
			local musicId = Audio.load(MUSIC_PATH) -- 117
			if musicId then -- 117
				audioInstanceRef.current = musicId -- 119
				Audio:play(musicId) -- 120
				songStartTimeSystem = App.totalTime -- 121
				isPlayingRef.current = true -- 122
				print("Music started") -- 123
			else -- 123
				print("Failed to load music") -- 125
				return -- 126
			end -- 126
		end -- 126
		local noteBeats = { -- 131
			4, -- 131
			8, -- 131
			12, -- 131
			16, -- 131
			20, -- 131
			24 -- 131
		} -- 131
		local nextNoteIndex = 0 -- 132
		while isPlayingRef.current do -- 132
			do -- 132
				local songTimeMs = getSongCurrentTimeMs() -- 135
				if songTimeMs == nil then -- 135
					coroutine.yield() -- 137
					goto __continue15 -- 138
				end -- 138
				local currentBeat = msToBeat(songTimeMs) -- 141
				local spawnThresholdBeat = msToBeat(songTimeMs + NOTE_SPAWN_OFFSET_MS) -- 142
				while nextNoteIndex < #noteBeats and noteBeats[nextNoteIndex + 1] <= spawnThresholdBeat do -- 142
					local beat = noteBeats[nextNoteIndex + 1] -- 149
					local screenY = beatToScreenY(beat, currentBeat) -- 150
					local noteNode = React.createElement( -- 151
						Tap, -- 152
						{x = 0, y = screenY}, -- 152
						React.createElement( -- 152
							"label", -- 152
							{ -- 152
								font = "sarasa-mono-sc-regular", -- 152
								size = 24, -- 152
								text = "Beat " .. tostring(beat), -- 152
								color = Color(4294967295), -- 152
								position = Vec2(0, 0) -- 152
							} -- 152
						) -- 152
					) -- 152
					noteNode.addTo(notesContainer) -- 162
					nextNoteIndex = nextNoteIndex + 1 -- 163
				end -- 163
				coroutine.yield() -- 169
			end -- 169
			::__continue15:: -- 169
		end -- 169
	end)) -- 114
	return {node = root} -- 173
end -- 107
local ____ = {x, string} -- 107
local ____ = any -- 107
return ____exports -- 107